//
//  BlockViewController.m
//  block深入浅出
//
//  Created by 周冰烽 on 2021/5/17.
//

#import "BlockViewController.h"

@interface BlockViewController ()

@property(nonatomic, copy) NSString * name;

@property(nonatomic, copy) void (^block)(void);

@property(nonatomic, copy) void (^block1)(BlockViewController *);

@end

@implementation BlockViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.name = @"jack";
    self.block1 = ^(BlockViewController *vc){
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            NSLog(@"%@", vc.name);
        });
    };
    self.block1(self);
}

- (void)test1 {
    self.name = @"jack";
    __weak typeof(self) ws = self;
    self.block = ^{
        __strong typeof(ws) ss = ws;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            NSLog(@"%@", ss.name);
        });
    };
    self.block();
}

- (void)test2 {
    self.name = @"jack";
    __block BlockViewController *vc = self;
    self.block = ^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            NSLog(@"%@", vc.name);
            vc = nil;
        });
    };
    self.block();
}

- (void)dealloc {
    NSLog(@"%s", __func__);
}



@end
